package com.itheima.service.impl;

import com.itheima.mapper.DeptMapper;
import com.itheima.pojo.Dept;
import com.itheima.service.DeptService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

/**
 * @Author: 渣哥
 * @CreateTime: 2025/5/26  16:32
 * @Description:
 */

@Service
public class DeptServiceImpl implements DeptService {
   @Autowired
    private DeptMapper deptMapper;
   @Override
    public List<Dept> findAll() {
        return deptMapper.findAll();
    }

    @Override
    public void deleteId(Integer id) {
       deptMapper.deleteId(id);
    }

    @Override
    public void add(Dept dept) {
       //1.补全基础属性-createTime，updateTime
        dept.setCreateTime(LocalDateTime.now());
        dept.setUpdateTime(LocalDateTime.now());
        //2.调用mapper层方法
        deptMapper.add(dept);
    }

    @Override
    public Dept findById(Integer id) {
        return deptMapper.findById(id);

    }

    @Override
    public void update(Dept dept) {
       //1、补全基本信息
        dept.setUpdateTime(LocalDateTime.now());
        //2、调用mapper层方法
        deptMapper.update(dept);
    }

}
